export const STOCKS = [
  {
    value: 1,
    label: '东南',
    children: [
      {
        value: 2,
        label: '上海',
      },
      {
        value: 7,
        label: '江苏',
      },
      {
        value: 12,
        label: '浙江',
      },
    ],
  },
  {
    value: 17,
    label: '西北',
    children: [
      {
        value: 18,
        label: '陕西',
      },
      {
        value: 21,
        label: '新疆维吾尔族自治区',
      },
    ],
  },
];

export const STOCKS_FORMAT = (ids) => {
  const idArr = ids.split(',');
  return findChild(STOCKS, idArr, 1).join(' / ');
};

function findChild(stocks, idArr, level) {
  let result = [];
  if (!stocks) return result;

  stocks.forEach((stock) => {
    const index = idArr.indexOf(stock.value.toString());

    if (index > -1) {
      result.push(stock.label);
    }
    if (stock.children) {
      result = result.concat(findChild(stock.children, idArr, level + 1));
    }
  });
  return result;
}
